package edu.sysu.cshare.dao;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import org.hibernate.Session;

import edu.sysu.cshare.util.HibernateSessionFactory;
@Entity
@Table(name="T_COURSE")
public class Course implements Serializable {
	private String examDesc;
	private List<Homework> homeworks = new ArrayList<Homework>();
	private long id;
	private String name;
	private int points;
	private List<User> students = new ArrayList<User>();
	private User teacher;
	private String type;
	public Course(){
		
	}
	public static Course  getCourseById(long id){
		Session ss= HibernateSessionFactory.getSession();
		return (Course) ss.load(Course.class, id);
	}
	/**
	 * 
	 * @param name 课程名称
	 * @param type 课程类型
	 * @param points 课程学分
	 * @param examDesc 考试说明
	 */
	public Course(String name, String type, int points, String examDesc) {
		super();
		this.examDesc = examDesc;
		this.name = name;
		this.points = points;
		this.type = type;
	}
	public String getExamDesc() {
		return examDesc;
	}
	
	@OneToMany(mappedBy="course")
	public List<Homework> getHomeworks() {
		return homeworks;
	}
	@Id
	@GeneratedValue
	public long getId() {
		return id;
	}
	public String getName() {
		return name;
	}
	public int getPoints() {
		return points;
	}
	@ManyToMany(mappedBy="courses"
		,targetEntity=User.class)
	public List<User> getStudents() {
		return students;
	}
	@OneToOne
	public User getTeacher() {
		return teacher;
	}
	public String getType() {
		return type;
	}
	public void setExamDesc(String examDesc) {
		this.examDesc = examDesc;
	}
	public void setHomeworks(List<Homework> homeworks) {
		this.homeworks = homeworks;
	}
	public void setId(long id) {
		this.id = id;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	public void setPoints(int points) {
		this.points = points;
	}

	
	public void setStudents(List<User> students) {
		this.students = students;
	}
	
	public void setTeacher(User teacher) {
		this.teacher = teacher;
	}
	public void setType(String type) {
		this.type = type;
	}
	@Override
	public String toString() {
		return "Course [examDesc=" + examDesc + ", id=" + id + ", name=" + name
				+ ", points=" + points + ", type=" + type + "]";
	}
	
}
